Git Cheatsheet
Getting started:
git clone [your-copied-url] - If your repository does not exist locally, get the link from GitHub and clone it to your local machine
git init - make the current directory a Git repository
Branches:
git branch - lists all local branches (you are in the one marked with *)
git branch -a - lists all local and remote branches (you are in the one marked with *)
git switch [branch-name] (or git checkout [branch-name]) - switch to that branch (files are updated to match the selected branch)
git switch -c [new-branch-name] (or git checkout -b [new-branch-name]) - create and switch to a new branch
git branch -d [branch-name] - delete branch locally
git merge [branch-name] - merges the given branch into your current branch
Committing changes:
git add [path/file-name] - stage a file (you can also stage all changes by using . as file name: git add . )
git reset [path/file-name] - unstage a file
git commit -m "[your-commit-message]" - commit your changes with a message (55 characters)
git push - uploads the commits of your current branch (if your branch also exists on the remote)
git push -u origin [branch-name] - uploads the commits of the given branch (use this if your branch does not exist on the remote)
Downloading changes:
git fetch - copies the files of the remote repository into your local repository
git pull - copies the files of the remote repository directly into your workspace (and your local repository)
Other:
git status - shows which changes are staged and which are not
git restore [file-name] - reset the unstaged file to the last commit
Sources
| [1] |
Source1 |
| [2] | GitHub |
| [3] | nobledesktop |